package com.lsw.jgyf.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.lsw.Base.BaseHolder;
import com.lsw.Base.BaseSimpleAdapter;
import com.lsw.jgyf.R;
import com.lsw.jgyf.model.OrderModel;
import com.lsw.jgyf.util.GlideUtils;

/**
 * Created by Administrator on 2018/7/12 0012.
 */

public class MyOrderAdapter extends BaseSimpleAdapter<OrderModel.DataEntity> {
    public MyOrderAdapter(Context context) {
        super(context);
    }

    @Override
    protected BaseHolder<OrderModel.DataEntity> getHolder() {
        return new BaseHolder<OrderModel.DataEntity>() {
            ImageView image;
            TextView tv_shibai;
            TextView tv_number;
            TextView tv_name;
            TextView tv_price;
            TextView tv_sucess;

            @Override
            public void bindViews(View parentView) {
                image = parentView.findViewById(R.id.image);
                tv_shibai = parentView.findViewById(R.id.tv_shibai);
                tv_number = parentView.findViewById(R.id.tv_number);
                tv_name = parentView.findViewById(R.id.tv_name);
                tv_price = parentView.findViewById(R.id.tv_price);
                tv_sucess = parentView.findViewById(R.id.tv_sucess);
            }

            @Override
            public void bindData(OrderModel.DataEntity item, int position) {
                GlideUtils.loadImageView(context, item.getImg(), image);
                tv_number.setText("订单编号：" + item.getOrder_num());
                tv_name.setText(item.getBrand_name() + " " + item.getPhone_name());
                tv_price.setText(item.getReal_money());
                if (item.getStatus() == 1) {
                    tv_sucess.setVisibility(View.VISIBLE);
                    tv_shibai.setVisibility(View.VISIBLE);
                    tv_sucess.setText("通过审核");
                    tv_shibai.setText("审核失败");
                } else if (item.getStatus() == 2) {
                    tv_sucess.setVisibility(View.VISIBLE);
                    tv_shibai.setVisibility(View.INVISIBLE);
                    tv_sucess.setText("已审核");
                    tv_shibai.setText("审核失败");
                } else if (item.getStatus() == 3) {
                    tv_sucess.setVisibility(View.VISIBLE);
                    tv_shibai.setVisibility(View.INVISIBLE);
                    tv_sucess.setText("已拒绝");
                    tv_shibai.setText("审核失败");
                }
                tv_shibai.setOnClickListener(v -> {
                    if (adapterRefresh != null)
                        adapterRefresh.onRefreshAdapter(position, 1);
                });
                tv_sucess.setOnClickListener(v -> {
                    if (item.getStatus() == 1) {
                        if (adapterRefresh != null)
                            adapterRefresh.onRefreshAdapter(position, 2);
                    }
                });

            }
        };
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.item_my_order;
    }
}
